package main

import (
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"log"
	"time"
)

type BlockRequest struct {
	Msg       []string
	Timestamp int64
}

var Br *BlockRequest

func init() {
	Br = new(BlockRequest)
}

func main() {
	Br.Msg = []string{"aaaaa", "bbbbbbbbb"}
	Br.Timestamp = time.Now().Unix()

	digest := getDigest(*Br)
	fmt.Println("digest1:", digest)
	send(*Br, digest)
}

func send(b BlockRequest, d string) {
	d2 := getDigest(b)
	if d2 != d {
		fmt.Println("aa:", d, d2)
	}

}

func getDigest(request BlockRequest) string {
	b, err := json.Marshal(request)
	if err != nil {
		log.Panic(err)
	}
	hash := sha256.Sum256(b)
	//进行十六进制字符串编码
	return hex.EncodeToString(hash[:])
}
